import Vue from 'vue'
import App from './App.vue'
import router from './router'



import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

import axios from 'axios'

axios.defaults.baseURL = 'http://localhost:3000';

axios.interceptors.request.use(config=>{
  config.headers.Authorization = localStorage.getItem('token')
  return config
})
Vue.prototype.$http = axios

router.beforeEach((to, from, next) => {
  // to and from are both route objects. must call `next`.
  if(to.path !=='/login'&& !localStorage.getItem('token')){
    next('/login')
  }else{
    next()
  }
})

Vue.config.productionTip = false

new Vue({
  router,
  render: function (h) { return h(App) }
}).$mount('#app')
